package com.shop2cn.iapi.agentproducts.testcase;

import java.util.Arrays;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.GetSelectionConditionListBean;
import com.shop2cn.iapi.agentproducts.parameter.SaveSelectionConditionBean;
import com.shop2cn.iapi.agentproducts.service.GetSelectionConditionListCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
/**
*查询选货筛选条件列表Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetSelectionConditionList{
	private static GetSelectionConditionListBean getselectionconditionlistBean;
	private static GetSelectionConditionListCall getselectionconditionlistCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询选货筛选条件列表Test");
	}

	@Before
	public void caseUp() {
		getselectionconditionlistBean=new GetSelectionConditionListBean();
		getselectionconditionlistCall=new GetSelectionConditionListCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getselectionconditionlistCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	private int MchId=501163178;
	private int AgentId = 501163179;
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetSelectionConditionList_001() {
		Logger.start(true,"下级+上级筛选条件");
		try {
			
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(MchId, "", true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			
			SaveSelectionConditionBean initSaveSelectionCondition = AddAgentProductCallService.InitSaveSelectionCondition(MchId, AgentId, 1);
			initSaveSelectionCondition.setBrandIdList(Arrays.asList(addAgentProductBean.getBrandId()));
			AddAgentProductCallService.SaveSelectionCondition(initSaveSelectionCondition);
			
			getselectionconditionlistBean.setAgentId(AgentId);
			getselectionconditionlistBean.setSupplierId(MchId);
			
			getselectionconditionlistCall.setData(getselectionconditionlistBean);
			getselectionconditionlistCall.callService();			
			Logger.verifyEquals("200", getselectionconditionlistCall.getString("code"), "验证code");
			JsonObject conditions = getselectionconditionlistCall.getJsonObject().getAsJsonObject("data").getAsJsonArray("conditions").get(0).getAsJsonObject();
			Logger.verifyEquals(MchId,conditions.get("supplierId").getAsInt(),"验证supplierId");
			Logger.verifyEquals(1,conditions.get("scope").getAsInt(),"验证scope");
			Logger.verifyEquals(addAgentProductBean.getBrandId(),conditions.getAsJsonArray("brandIdList").get(0).getAsInt(),"验证brandIdList");
//			Logger.verifyEquals("[]",conditions.get("firstCategoryIdList").toString(),"验证firstCategoryIdList");
//			Logger.verifyEquals("[]",conditions.get("depotIdList").toString(),"验证depotIdList");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetSelectionConditionList_002() {
		Logger.start(true,"下级查询筛选条件");
		try {
			
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(MchId, "", true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			
			SaveSelectionConditionBean initSaveSelectionCondition = AddAgentProductCallService.InitSaveSelectionCondition(MchId, AgentId, 1);
			initSaveSelectionCondition.setBrandIdList(Arrays.asList(addAgentProductBean.getBrandId()));
			AddAgentProductCallService.SaveSelectionCondition(initSaveSelectionCondition);
			
			getselectionconditionlistBean.setAgentId(AgentId);
			getselectionconditionlistBean.setSupplierId(null);
			
			getselectionconditionlistCall.setData(getselectionconditionlistBean);
			getselectionconditionlistCall.callService();			
			Logger.verifyEquals("200", getselectionconditionlistCall.getString("code"), "验证code");
			JsonObject conditions = getselectionconditionlistCall.getJsonObject().getAsJsonObject("data").getAsJsonArray("conditions").get(0).getAsJsonObject();
			Logger.verifyEquals(MchId,conditions.get("supplierId").getAsInt(),"验证supplierId");
			Logger.verifyEquals(1,conditions.get("scope").getAsInt(),"验证scope");
			Logger.verifyEquals(addAgentProductBean.getBrandId(),conditions.getAsJsonArray("brandIdList").get(0).getAsInt(),"验证brandIdList");
//			Logger.verifyEquals("[]",conditions.get("firstCategoryIdList").toString(),"验证firstCategoryIdList");
//			Logger.verifyEquals("[]",conditions.get("depotIdList").toString(),"验证depotIdList");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetSelectionConditionList_003() {
		Logger.start(true,"下级查询筛选条件，范围为所有/条件为空");
		try {
			
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(MchId, "", true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			
			SaveSelectionConditionBean initSaveSelectionCondition = AddAgentProductCallService.InitSaveSelectionCondition(MchId, AgentId, 0);
			AddAgentProductCallService.SaveSelectionCondition(initSaveSelectionCondition);
			
			getselectionconditionlistBean.setAgentId(AgentId);
			getselectionconditionlistBean.setSupplierId(MchId);
			
			getselectionconditionlistCall.setData(getselectionconditionlistBean);
			getselectionconditionlistCall.callService();			
			Logger.verifyEquals("200", getselectionconditionlistCall.getString("code"), "验证code");
			JsonObject conditions = getselectionconditionlistCall.getJsonObject().getAsJsonObject("data").getAsJsonArray("conditions").get(0).getAsJsonObject();
			Logger.verifyEquals(MchId,conditions.get("supplierId").getAsInt(),"验证supplierId");
			Logger.verifyEquals(0,conditions.get("scope").getAsInt(),"验证scope");
			Logger.verifyEquals(0,conditions.getAsJsonArray("brandIdList").size(),"验证brandIdList");
			Logger.verifyEquals(0,conditions.getAsJsonArray("firstCategoryIdList").size(),"验证firstCategoryIdList");
			Logger.verifyEquals(0,conditions.getAsJsonArray("depotIdList").size(),"验证depotIdList");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetSelectionConditionList_004() {
		Logger.start(true,"查询筛选条件，上级id错误，查询为null  scope为0");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(MchId, "", true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			
			SaveSelectionConditionBean initSaveSelectionCondition = AddAgentProductCallService.InitSaveSelectionCondition(MchId, AgentId, 1);
			initSaveSelectionCondition.setBrandIdList(Arrays.asList(addAgentProductBean.getBrandId()));
			AddAgentProductCallService.SaveSelectionCondition(initSaveSelectionCondition);
			
			getselectionconditionlistBean.setAgentId(AgentId);
			getselectionconditionlistBean.setSupplierId(112233);
			
			getselectionconditionlistCall.setData(getselectionconditionlistBean);
			getselectionconditionlistCall.callService();			
			Logger.verifyEquals("200", getselectionconditionlistCall.getString("code"), "验证code");
			JsonObject conditions = getselectionconditionlistCall.getJsonObject().getAsJsonObject("data").getAsJsonArray("conditions").get(0).getAsJsonObject();
			Logger.verifyEquals(112233,conditions.get("supplierId").getAsInt(),"验证supplierId");
			Logger.verifyEquals(0,conditions.get("scope").getAsInt(),"验证scope");
			Logger.verifyEquals(true,conditions.get("brandIdList").isJsonNull(),"验证brandIdList");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
}